const helper = require("../../../utils/helper.js");

Page({

  /**
   * 页面的初始数据
   */
  data: {
    avatar: '/images/user.jpg',
    nickname: 'YOUYOU',
    sex: ['男', '女'],
    sexIdx: 0,
    identityList: ['平面模特', '演员', '主播', '主持人'],
    identityIdx: 0, // 身份
    region: ['广东', '广州'],
    heightList: [],
    heightIdx: 0, // 身高
    weightList: [],
    weightIdx: 0, // 体重
    dimensionsList: [],
    chestIdx: 0, // 胸围
    waistIdx: 0, // 腰围
    hipIdx: 0,   // 臀围
    shoesSizeList: [],
    shoesSizeIdx: 5, // 鞋码
    identityTags: [
      {
        id: '1',
        name: '平面模特',
        checked: false,
      },
      {
        id: '2',
        name: '主播',
        checked: false,
      },
      {
        id: '3',
        name: '演员',
        checked: false,
      },
      {
        id: '4',
        name: '经纪人',
        checked: false,
      },
      {
        id: '5',
        name: '主持人',
        checked: false,
      },
      {
        id: '6',
        name: 'DJ',
        checked: false,
      },
      {
        id: '7',
        name: '商家',
        checked: false,
      },
      {
        id: '8',
        name: '特型演员',
        checked: false,
      },
      {
        id: '9',
        name: '发型模特',
        checked: false,
      },
      {
        id: '10',
        name: '群演',
        checked: false,
      },
      {
        id: '11',
        name: '礼仪模特',
        checked: false,
      },
      {
        id: '12',
        name: '商演',
        checked: false,
      },
      {
        id: '13',
        name: '舞蹈',
        checked: false,
      }
    ],
    notices: [
      {
        id: '1',
        name: '广告拍摄',
        checked: false
      },
      {
        id: '2',
        name: '晚会礼仪',
        checked: false
      },
      {
        id: '3',
        name: '派对活动',
        checked: false
      },
      {
        id: '4',
        name: '直播合作',
        checked: false
      },
      {
        id: '5',
        name: '商业代言',
        checked: false
      },
      {
        id: '6',
        name: '商业代言',
        checked: false
      },
      {
        id: '7',
        name: '商业代言',
        checked: false
      },
      {
        id: '8',
        name: '商业代言',
        checked: false
      },
      {
        id: '9',
        name: '商业代言',
        checked: false
      },
      {
        id: '10',
        name: '商业代言',
        checked: false
      },
      {
        id: '11',
        name: '商业代言',
        checked: false
      },
      {
        id: '12',
        name: '商业代言',
        checked: false
      }
    ],
    fromPage: '' // 个人主页跳转来或者模板跳转来
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const tempFilePathsInfo = helper.gettingStorage('TEMPFILEPATHS_INFO');
    this.setData({
      tempFilePathsInfo,
      fromPage: options.fromPage
    });
    this.init();
  },

  // 数据初始化
  init: function() {
    const heightList = [];
    const weightList = [];
    const shoesSizeList = [];
    const dimensionsList = [];
    for (let i = 50; i < 221; i++) {
      heightList.push(i);
    }
    for (let i = 20; i <= 90; i++) {
      weightList.push(i);
    }
    for (let i = 30; i <= 48; i++) {
      shoesSizeList.push(i);
    }
    const tempList = [];
    for (let i = 40; i <= 120; i++) {
      tempList.push(i);
    }
    dimensionsList[0] = tempList;
    dimensionsList[1] = tempList;
    dimensionsList[2] = tempList;
    this.setData({
      heightList,
      weightList,
      shoesSizeList,
      dimensionsList
    })
  },

  // 头像
  chooseAvatar: function () {
    const self = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const avatar = res.tempFilePaths[0];
        self.setData({
          avatar
        });
      }
    });
  },

  // 昵称
  nicknameChange: function (e) {
    this.setData({
      nickname: e.detail.value
    })
  },

  // 性别
  changeSex: function(e) {
    this.setData({
      sexIdx: e.detail.value
    })
  },

  // 生日
  bindDateChange(e) {
    this.setData({
      birthday: e.detail.value
    })
  },

  // 身份
  bindIdentityChange: function(e) {
    this.setData({
      identityIdx: e.detail.value
    })
  },

  // 地区
  changeRegion: function(e) {
    this.setData({
      region: e.detail.value
    })
  },

  // 身高
  heightChange: function(e) {
    this.setData({
      heightIdx: e.detail.value
    })
  },

  // 体重
  weightChange: function (e) {
    this.setData({
      weightIdx: e.detail.value
    })
  },

  // 三围
  bindMultiPickerChange: function(e) {
    const values = e.detail.value;
    this.setData({
      chestIdx: values[0],
      waistIdx: values[1],
      hipIdx: values[2]
    })
  },

  // 鞋码
  shoesSizeChange: function(e) {
    this.setData({
      shoesSizeIdx: e.detail.value
    })
  },

  // 工作经历
  bindDescChange: function(e) {
    this.setData({
      exprience: e.detail.value
    })
  },

  // 专业标签
  identityTagsSelect: function (e) {
    const tagIdx = e.currentTarget.dataset.tagIdx;
    let identityTags = this.data.identityTags;
    identityTags[tagIdx].checked = !identityTags[tagIdx].checked;
    this.setData({
      identityTags
    })
  },

  noticesSelect: function (e) {
    const tagIdx = e.currentTarget.dataset.tagIdx;
    let notices = this.data.notices;
    notices[tagIdx].checked = !notices[tagIdx].checked;
    this.setData({
      notices
    })
  },

  // 保存跳转制作卡片
  toMakeCard: function(e) {
    const { 
      tempFilePathsInfo,
      avatar,
      nickname,
      heightList, 
      heightIdx, 
      weightList, 
      weightIdx,
      shoesSizeList, 
      shoesSizeIdx, 
      dimensionsList, 
      chestIdx, 
      waistIdx,
      hipIdx,
      fromPage
    } = this.data;
    if (fromPage === 'user') {
      wx.switchTab({
        url: '/pages/user/index',
      })
      return;
    }
    let userInfo = {
      avatar,
      nickname,
      weight: weightList[weightIdx],
      height: heightList[heightIdx],
      chest: dimensionsList[0][chestIdx],
      waist: dimensionsList[1][waistIdx],
      hip: dimensionsList[2][hipIdx],
      shooseSize: shoesSizeList[shoesSizeIdx]
    };
    let userInfoStr = JSON.stringify(userInfo);
    helper.log('userInfoStr : ',  userInfoStr);
    if (tempFilePathsInfo.type === 1) {
      wx.navigateTo({
        url: `/pages/drawCard/vertical/vertical${tempFilePathsInfo.imgCount}/index?userInfoStr=${userInfoStr}`,
      })
    }
  }
})